package com.haoting.blogservice.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.haoting.blogservice.entity.Blog;
import com.haoting.blogservice.entity.vo.BlogIndexVo;
import com.haoting.blogservice.entity.vo.BlogInfoVo;
import com.haoting.blogservice.entity.vo.BlogPublishVo;
import com.haoting.blogservice.entity.vo.BlogQuery;
import com.haoting.blogservice.entity.vo.BlogWebVo;
import com.haoting.blogservice.entity.vo.FrontAuthorVo;
import com.haoting.blogservice.entity.vo.FrontBlogQuery;
import com.haoting.blogservice.entity.vo.HotAuhtor;
import com.haoting.blogservice.mapper.BlogMapper;
import com.haoting.blogservice.service.BlogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.haoting.service.exceptionhandler.BlogException;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author tingting
 * @since 2020-12-21
 */
@Service
public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements BlogService {

    @Override
    public String saveBlogInfo(BlogInfoVo blogInfoVo) {
        Blog blogInfo = new Blog();
        BeanUtils.copyProperties(blogInfoVo,blogInfo);
        int insert = baseMapper.insert(blogInfo);
        if(insert <= 0 ){
            throw new BlogException(20001,"添加文章失败");
        }
        String bid = blogInfo.getId();
        return bid;
    }

    @Override
    public List<BlogIndexVo> gethotblogVo() {
        return baseMapper.gethotblogVo();
    }

    @Override
    public BlogPublishVo publishBlogInfo(String id) {
        BlogPublishVo blogPublishVo = baseMapper.getPublishCourseInfo(id);


        return blogPublishVo;
    }

    @Override
    public Page<BlogInfoVo> getPageVo(Page<BlogInfoVo> page, BlogQuery blogQuery) {

        return  baseMapper.getPageVo(page,blogQuery);
    }

    @Override
    public List<BlogIndexVo> getBlogIndexVo() {
        return baseMapper.getBlogIndexVo();
    }

    @Override
    public List<HotAuhtor> getHotAuthor() {
        return baseMapper.getHotAuthor();
    }

    @Override
    public Page<BlogIndexVo> getblogFront(Page<BlogIndexVo> page, FrontBlogQuery frontBlogQuery) {
        return baseMapper.getblogFront(page,frontBlogQuery);
    }

    @Override
    public BlogWebVo getFrontBlogInfo(String blogId) {
        return baseMapper.getFrontBlogInfo(blogId);
    }

    @Override
    public FrontAuthorVo getAuthorCount(String authorId) {
        return baseMapper.getAuthorCount(authorId);
    }

    @Override
    public void addSupportCount(String blogId) {
        baseMapper.addSupportCount(blogId);
    }

    @Override
    public void collectionUpdate(String blogId) {
        baseMapper.collectionUpdate(blogId);
    }

    @Override
    public void addlook(String blogId) {
        baseMapper.addlook(blogId);
    }
}
